<?php
if(isset($_REQUEST['tag_id'])) {
	$tagsString = "select name,rss_id,status from tags where tag_id=".$_REQUEST['tag_id'];
	$tagsQuery = dbSelect($tagsString) or die("Error en select ".$tagsString." ".mysql_error());
	$tagsResult = mysql_fetch_array($tagsQuery);
} else {
	$tagsResult['name'] = $_REQUEST['nombre'];
	$tagsResult['rss_id'] = $_REQUEST['rss'];
	$tagsResult['status'] = $_REQUEST['status'];
}
?>

<table border="0" cellpadding="0" cellspacing="4" width="100%">
	<tr>
		<td height="50">
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr>
					<td align="center" class="titulo">ALTA DE TAG</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td>
			<form name="frm_alta" method="post" action="tags/operations.php" onSubmit="javascript:return validate_empty(document.frm_alta.nombre);">
				<input type="hidden" name="tag_id" value="<?php echo $_REQUEST['tag_id']; ?>">
				<input type="hidden" name="axn" value="<?php echo $_REQUEST['axn']; ?>">
				<table border="0" cellpadding="0" cellspacing="4" align="center">
					<tr>
						<td align="right">Nombre</td>
						<td><input class="input" type="text" name="nombre" value="<?php echo $tagsResult['name']; ?>" style="width:300px;"></td>
					</tr>
					<tr>
						<td align="right">Rss</td>
						<td>
							<select name="rss" class="input">
								<option value=""></option>
							<?php
							$rssString = "select rss_id, url from rss order by url";
							$rssQuery = dbSelect($rssString) or die("Error en ".$rssString." ".mysql_error());
							while($rssResult = mysql_fetch_array($rssQuery)) {
								if($tagsResult['rss_id']==$rssResult['rss_id']) {
									echo "<option value='".$rssResult['rss_id']."' selected>".$rssResult['url']."</option>";
								} else {
									echo "<option value='".$rssResult['rss_id']."'>".$rssResult['url']."</option>";
								}
							}
							?>
							</select>
						</td>
					</tr>
					<tr>
						<td align="right">Status</td>
						<td>
							<select name="status" class="input">
								<option value="A" <?php echo (isset($tagsResult['status']) && $tagsResult['status']=='A')?'selected':''; ?> >Activo</option>
								<option value="I" <?php echo (isset($tagsResult['status']) && $tagsResult['status']=='I')?'selected':''; ?> >Inactivo</option>
							</select>
						</td>
					</tr>
					<tr>
						<td height="10"></td>
					</tr>
					<tr>
						<td align="right"></td>
						<td align="center">
							<input class="input" type="submit" name="guardar" value="Guardar">
							<input class="input" type="button" name="cancelar" value="Cancelar" onClick="javascript:window.location.href='index.php?admin=tags';">
						</td>
					</tr>
				</table>
			</form>
		</td>
	</tr>
</table>